import io.xjar.XConstants;
import io.xjar.XKit;
import io.xjar.boot.XBoot;
import io.xjar.key.XKey;

import java.io.File;

/**
 * @author: NMY
 * @Date: 2021/6/28
 * @Time: 14:37
 */
public class Main {
    public static void main(String[] args) throws Exception {

        String password = "M1f978ba74ddfe2_";
        final String self = "encrypt.jar";
        final String suffix = ".jar";

        if (args.length == 1) {
            password = args[0];
        }

        File file = new File(System.getProperty("user.dir"));
        File[] files = file.listFiles();
        if (files.length == 0) {
            return;
        }

        for (File f : files) {
            if (f.isDirectory()) {
                continue;
            }

            if (!f.getName().endsWith(self) && f.getName().endsWith(suffix)) {
                encrypt(f, password);
            }
        }
    }

    public static void encrypt(File file, String password) throws Exception {
        String src = file.getAbsolutePath();
        String dest = src.substring(0, src.lastIndexOf(".jar")) + "-encrypt.jar";
        XKey xKey = XKit.key(password);
        XBoot.encrypt(src, dest, xKey, XConstants.MODE_NORMAL);
    }
}
